
import {observable,action ,computed } from 'mobx'
import { ajax } from './../utils/ajax';


class Data{

    // state  可观察状态（State）
    @observable count = 1000;
    @observable city = "美丽的黄石大冶"
    @observable word = "wh2114 - daydayup "
    @observable test = "测试-TESt"
    @observable mv = []  

    @action countAdd = ()=>{
        this.count++;
        console.log(this.count  )
    }

    @action countDesc = ()=>{
        this.count--;
    }

    @action changeCount = payload=>{
        this.count+= payload 
    }

    @action changeCity = city=>{
        this.city = city 
    }

    @action changeWord = word =>{
        this.word = word ; 
    }

    @action changeTest = async ()=>{
        let res = await ajax.get("http://localhost:3000/api/test")
        this.test = res.data.msg ;
    }

    @action getMvList = async ()=>{
        let res = await ajax.get("http://localhost:3000/movie")
        this.mv = res.data.result 
    }

    @action changeNewCount = payload=>{
        this.newCount = payload 
    }

    // 依赖的是 count 
    @computed get newCount(){
        return this.count * 10 + 800
    }

    // 监听值得主动改变 
    set newCount(v){
        console.log('主动修改了 newcount  newCOunt 的新值 ' + v)
        this.count = v;
    }

}

export default new Data()